package controlLayer;
import modelLayer.*;
import modelLayer.Exceptions.*;

public class AccountCtrl
{
    private Accounting accounting;
    
    public AccountCtrl() {
        accounting=Accounting.getInstance();
    }
    public void createAccount( String name, double balance) throws DuplicateAccountNameException {
        Account a=new Account(name, balance);
        accounting.getInstance().addAccount(a);
    }
    
    public void transferFunds(String from, String to, double amount) throws BalanceUnderrunException{
        if(amount> accounting.getInstance().findByName(from).getBalance()) {
            throw new BalanceUnderrunException("Your are trying to transfer more money than you have ",  accounting.getInstance().findByName(from).getBalance(), amount);
        }
        accounting.getInstance().findByName(from).withdraw(amount);
        accounting.getInstance().findByName(to).deposit(amount);
    }
    public void showInfo(String name) {
        accounting.getInstance().showInfo(name);
    }
}
